<p><a href="#" id="toggle">Show/hide extra fields</a></p>
<?php
	echo $form->input('template_id');
	echo $form->hidden('date');
	echo $form->input('time_total');
?>

<?php 
	echo $form->input('heartrate');
	echo $form->input('distance');
?>
<div class="extra-fields">
<?php

	echo $form->input('kcal');
	echo $form->input('tss');
	echo $form->input('tags');
	echo $form->input('description');
?>

</div>


<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery('.extra-fields').hide();
		jQuery('#toggle').toggle(
		  function () {
		    $('.extra-fields').fadeIn();
		  },
		  function () {
		    $('.extra-fields').fadeOut();
		  }
		);
		
		<?php if($this->params['isAjax']): ?>
		$("form").submit(function() {
			var formData = $(this).serialize();
			var url = $(this).attr('action');
			var date = $('#WorkoutDate').val();
			//event-holder-2009-10-30
			//var container = ;
			console.log(url);
			//console.log(formData);
			
			jQuery.ajax({
			   type: "POST",
			   url: url,
			   data: formData,
			   success: function(data){
				jQuery('#event-holder-'+date).html(data);
				//parent().get(0) .effect("highlight", {}, 3000);
				jQuery('#event-holder-'+date).parent().effect("highlight", {}, 6000);
				jQuery('.nyroModalClose').click();
			     //alert( "Data Saved: " + data );
			   }
			 });
			
			return false;
	    });
		<?php endif; ?>
		
		<?php if(isset($auto_update) and $auto_update): ?>
		/* Workout templates update */
		var url = "<?php echo $html->url(array('action'=>'json_get_template'))?>";
		jQuery("#WorkoutTemplateId").change(function() {
			var val = jQuery("#WorkoutTemplateId option:selected").val();
			//console.log(url+"/"+ val);
			jQuery.getJSON(url+"/"+ val, function(data){
				
				//if(jQuery("#WorkoutTimeTotal").val() == "")
					jQuery("#WorkoutTimeTotal").val(data.Template.initial_time_total);
				//jQuery("#WorkoutTimeInPowerZone").val(data.Template.initial_time_in_power_zone);
				//if(jQuery("#WorkoutHeartrate").val() == "")
					jQuery("#WorkoutHeartrate").val(data.Template.initial_heartrate);
				//if(jQuery("#WorkoutDistance").val() == "")
					jQuery("#WorkoutDistance").val(data.Template.initial_distance);
				//if(jQuery("#WorkoutKcal").val() == "")
					jQuery("#WorkoutKcal").val(data.Template.initial_kcal);
				//if(jQuery("#WorkoutTss").val() == "")
					jQuery("#WorkoutTss").val(data.Template.initial_tss);
			});
		}); 
		jQuery("#WorkoutTemplateId").change();
		<?php endif; ?>
	});
</script>